#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>

#define FOR(i,a,n) for(int i=a,_n(n);i<_n;++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

struct Resident
{
    string name;
    int val,type;
    Resident(string n="",int a=0,int b=0)
    {
        name = n, val = a, type = b;
    }
    bool operator< (Resident rb) const
    {
        return val > rb.val;
    }
};
struct Item
{
    string name;
    int atk,def,res,size,type;
    vector<Resident*> slot;
    Item(string n="",int a=0,int b=0,int c=0,int d=0,int e=0)
    {
        name = n;
        atk = a, def = b, res = c, size = d, type = e;
    }
    void Add(Resident* resd)
    {
        slot.push_back(resd);
    }
    bool Full()
    {
        return size==slot.size();
    }
    int Cal()
    {
        int res = 0;
        REP(i,slot.size()) if(slot[i]->type==type)
        {
            res += slot[i]->val;
        }
        return res;
    }
    void Print()
    {
        cout<<name<<" "<<slot.size()<<" ";
        REP(i,slot.size()) cout<<slot[i]->name<<" ";
        cout<<endl;
    }
    bool operator < (Item ib) const
    {
        return size > ib.size;
    }
};
vector<Item> item[3];
vector<Resident> resident[3];
map<string,Item*> getItem;
int main()
{
    int n,k;
    REP(i,3) item[i].reserve(101),resident[i].reserve(1001);
    while(cin>>n)
    {
        REP(i,3) item[i].clear(),resident[i].clear();
        getItem.clear();
        REP(i,n)
        {
            string name,type;
            int atk,def,res,size;
            cin>>name>>type>>atk>>def>>res>>size;
            int tid = -1;
            if(type=="weapon") tid = 0;
            else if(type=="armor") tid = 1;
            else tid = 2;
            item[tid].push_back(Item(name,atk,def,res,size,tid));
            getItem[name] = &item[tid].back();
        }
        cin>>k;
        REP(i,k)
        {
            string name,type,bl;
            int val;
            cin>>name>>type>>val>>bl;
            Item* it = getItem[bl];
            int tid = -1;
            if(type=="gladiator") tid = 0;
            else if(type=="sentry") tid = 1;
            else tid = 2;
            resident[tid].push_back(Resident(name,val,tid));
            it->Add(&resident[tid].back());
            //printf("Add!! ");it->Print();
        }
        bool easy = true;
        REP(i,3) REP(j,item[i].size()) if(!item[i][j].Full()) easy = false;
        //REP(i,3) printf("resi[%d] size = %d\n",i,resident[i].size());
        //printf("easy = %s\n",easy?"true":"false");
        if(easy)
        {
            REP(i,3)
            {
                int tmax = -1;
                Item* it = NULL;
                REP(j,item[i].size())
                {
                    int t = item[i][j].Cal();
                    if(t>tmax)
                    {
                        t = tmax;
                        it = &item[i][j];
                    }
                }
                it->Print();
            }
        }
        else
        {
            REP(i,3)
            {
                sort(resident[i].begin(),resident[i].end());
                sort(item[i].begin(),item[i].end());
            }
            int pos[3]={0,0,0};
            REP(i,3)
            {
                Item& it = item[i][0];
                it.slot.clear();
                while(!it.Full()&&resident[i].size()!=pos[i])
                {
                    it.Add(&resident[i][pos[i]++]);
                    //printf("Add! "); it.Print();
                }
            }
            REP(i,3)
            {
                Item& it = item[i][0];
                REP(j,3)
                {
                    while(!item[i][0].Full()&&resident[j].size()!=pos[j])
                    {
                        it.Add(&resident[j][pos[j]++]);
                       // printf("Add! "); it.Print();
                    }
                }
            }
            REP(i,3) item[i][0].Print();
        }
    }
	return 0;
}
